#include "OLToolbar.h"
#include "OLButton.h"
#include "OLAppTemplateDefs.h"

#include <QtGui/QPainter>
#include <QtGui/QLinearGradient>
#include <QtGui/QHBoxLayout>

OLToolbar::OLToolbar(QWidget *parent) :
    QWidget(parent), m_drawBg(true)
{
    QHBoxLayout* layout = new QHBoxLayout(this);
    layout->setContentsMargins(1,1,1,1);
    layout->setSpacing(1);
    setLayout(layout);
}

void OLToolbar::paintEvent(QPaintEvent*)
{
//    QPainter p(this);

//    if( m_drawBg ) {
//        p.setPen(Qt::NoPen);
//        p.setBrush(OLStyles::toolbarBackgroundBrush(rect()));
//        p.drawRect(rect());

//        // draw toolbar horizonal outlines
//        p.setBrush(Qt::NoBrush);
//        p.setPen(OLStyles::buttonSeparator());
//        p.drawLine(0, 0, width(), 0);
//        p.drawLine(0, height()-1, width(), height()-1);
//    }

//    // draw separators between widgets
//    p.setPen(OLStyles::buttonSeparator());
//    QList<OLButton*> widgets = findChildren<OLButton*>();
//    int childCount = widgets.count();
//    for(int ii=0; ii<childCount-1; ++ii) {
//        OLButton* btn = widgets[ii];
//        if( btn->isVisible() ) {
//        int xpos = widgets[ii]->geometry().right()+1;
//        p.drawLine(xpos, 1, xpos, height());
//        }
//    }
}

void OLToolbar::disableButtons()
{
    QList<OLButton*> widgets = findChildren<OLButton*>();
    int childCount = widgets.count();
    for(int ii=0; ii<childCount; ++ii) {
        widgets[ii]->disable();
        }
}

void OLToolbar::enableButtons()
{
    QList<OLButton*> widgets = findChildren<OLButton*>();
    int childCount = widgets.count();
    for(int ii=0; ii<childCount; ++ii) {
        widgets[ii]->enable();
        }
}
